

import { ref, provide, watch, reactive } from 'vue';
import customSearchComponent from './customSearch.vue';




const initCustomSearch = (proxy) => {
    const context = {
        formInstance: ""
    };


    const customSearchTextAreaPlaceholder = proxy.$t("goods_archive.custom_search_placeholder")
    const formData = reactive({
        radio: 'sku',
        textAreaValue: '',
    })


    const rules = reactive({
        radio: [{ required: true, message: proxy.$t("goods_archive.custom_search_type_required"), },],
        textAreaValue: [{ required: true, message: proxy.$t("goods_archive.custom_search_value_required") }],

    })
    const customSearchHandle = reactive({
        search: () => {
            //搜索触发方法，在 父组件 会重写这个方法，点击customSearchComponent的搜索按钮时会执行被重写的方法，

        },

        clear: () => {
            //用来清除 表单数据，
            context.formInstance.value.resetFields();
        },
        getFormInstance: (formInstance) => {
            //customSearch组件会调用，并且获取组件中 表单 实例 ref，并存到context中
            context.formInstance = formInstance
        }
    });



    provide('customSearchFormData', formData);
    provide('customSearchRules', rules);
    provide('customSearchTextAreaPlaceholder', customSearchTextAreaPlaceholder);

    provide('customSearchHandle', customSearchHandle);//注入到customSearchComponent 中

    return {
        customSearchComponent,
        customSearchHandle,

    }

}



export {
    initCustomSearch

}





